﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Entity;
using BAL;
using Common;
using System.Collections.Generic;
namespace Web
{
    public partial class ExamPaperSelectSubPolicy : System.Web.UI.Page
    {
        protected int _QuestionTypeid = 0, _SubjectId = 0, _VersionId = 0, _ExamId = 0, _KnowId = 0, _DiffId = 0,page=1;
        protected string _TitleStr = "";
        protected decimal _Score = 0;
        private string ids = "";
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.QueryString["id"] != null && Request.QueryString["id"].Trim().Length > 0)
            {
                ids = Request.QueryString["id"];
                
            }
            if (Request.QueryString["page"] != null && Request.QueryString["page"].Trim().Length > 0)
            {
                if (PageValidate.IsNumber(Request.QueryString["page"]))
                {
                    page = int.Parse(Request.QueryString["page"]);
                }
            }
          
            if (Request.QueryString["DiffId"] != null && Request.QueryString["DiffId"].Trim().Length > 0)
            {
                if (PageValidate.IsNumber(Request.QueryString["DiffId"]))
                {
                    _DiffId = int.Parse(Request.QueryString["DiffId"]);
                }
            }

            if (Request.QueryString["KnowId"] != null && Request.QueryString["KnowId"].Trim().Length > 0)
            {
                if (PageValidate.IsNumber(Request.QueryString["KnowId"]))
                {
                    _KnowId = int.Parse(Request.QueryString["KnowId"]);
                }
            }

            if (Request.QueryString["QuestionTypeId"] != null && Request.QueryString["QuestionTypeId"].Trim().Length > 0)
            {
                if (PageValidate.IsNumber(Request.QueryString["QuestionTypeId"]))
                {
                    _QuestionTypeid = int.Parse(Request.QueryString["QuestionTypeId"]);
                }
            }

            if (Request.QueryString["SubjectId"] != null && Request.QueryString["SubjectId"].Trim().Length > 0)
            {
                if (PageValidate.IsNumber(Request.QueryString["SubjectId"]))
                {
                    _SubjectId = int.Parse(Request.QueryString["SubjectId"]);
                }
            }
            if (Request.QueryString["VersionId"] != null && Request.QueryString["VersionId"].Trim().Length > 0)
            {
                if (PageValidate.IsNumber(Request.QueryString["VersionId"]))
                {
                    _VersionId = int.Parse(Request.QueryString["VersionId"]);
                }
            }

            if (Request.QueryString["Score"] != null && Request.QueryString["Score"].Trim().Length > 0)
            {
                if (PageValidate.IsNumber(Request.QueryString["Score"]))
                {
                    _Score = int.Parse(Request.QueryString["Score"]);
                }
            }

            if (Request.QueryString["TitleStr"] != null && Request.QueryString["TitleStr"].Trim().Length > 0)
            {
                _TitleStr = Server.UrlDecode(Request.QueryString["TitleStr"]);
            }

            if (Request.QueryString["ExamId"] != null && Request.QueryString["ExamId"].Trim().Length > 0)
            {
                if (PageValidate.IsNumber(Request.QueryString["ExamId"]))
                {
                    _ExamId = int.Parse(Request.QueryString["ExamId"]);
                }
            }

            if (!Page.IsPostBack)
            {
                if (_ExamId > 0)
                {
                    try
                    {
                        IList<TestPaperPolicySubInfo> list = TestPaperPolicySub.GetListByExamPaperId(_ExamId);
                        this.drpSubPolicy.DataTextField = "Name";
                        this.drpSubPolicy.DataValueField = "Id";
                        this.drpSubPolicy.DataSource = list;
                        this.drpSubPolicy.DataBind();
                    }
                    catch
                    { 
                        
                    }
                }
            }
        }

        protected void btnSave_Click(object sender, EventArgs e)
        { 
           if(_ExamId>0 && this.drpSubPolicy.SelectedIndex!=-1)
           {
               try
               {
                   string[] arrrayTemp = ids.Split(',');
                   int max = Paper_Ques.GetMaxOrderIdValue(_ExamId, int.Parse(drpSubPolicy.SelectedValue));
                   foreach (string  item in arrrayTemp)
                   {
                       if (item != null && item != "" && item != "0")
                       {
                           max++;
                           Paper_QueInfo ps = new Paper_QueInfo { CreateDate = DateTime.Now, ExamPaperId = _ExamId, QuesId = int.Parse(item), SubPolicyId = int.Parse(this.drpSubPolicy.SelectedValue), OrderId = max };
                           Paper_Ques.Add(ps);
                       }
                   }
                   this.ClientScript.RegisterStartupScript(this.GetType(), "key", "WinRefresh();", true);
               }
               catch
               { 
               
               }
           }
        }
    }
}
